package com.homework1_4.itheima.controller;

import com.homework1_4.itheima.bean.Student;
import com.homework1_4.itheima.service.StudentService;
import com.homework1_4.itheima.service.impl.StudentServiceImpl;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

/*
    控制层测试类
 */
public class StudentController {
    //创建业务层对象
    private StudentService service = new StudentServiceImpl();

    //查询全部功能测试
    @Test
    public void selectAll() {
        List<Student> students = service.selectAll();
        for (Student stu : students) {
            System.out.println(stu);
        }
    }

    //根据id查询功能测试
    @Test
    public void selectById() {
        Student stu = service.selectById(3);
        System.out.println(stu);
    }

    //新增功能测试
    @Test
    public void insert() {
        Student stu = new Student(4,"赵六",26);
        Integer result = service.insert(stu);
        System.out.println(result);
    }

    //修改功能测试
    @Test
    public void update() {
        Student stu = new Student(4,"老王",16);
        Integer result = service.update(stu);
        System.out.println(result);
    }

    //删除功能测试
    @Test
    public void delete() {
        Integer result = service.delete(4);
        System.out.println(result);
    }

    //2.完成@Param的案例(根据姓名或年龄查询功能)
    @Test
    public void selectByNameOrAge() {
        List<Student> students = service.selectByNameOrAge("张三",24);
        for (Student stu : students) {
            System.out.println(stu);
        }
    }

//    3.完成动态SQL中的if标签,foreach标签,和sql片段的抽取
    @Test
    public void selectCondition(){
        Student stu = new Student(4);
        List<Student> list = service.selectCondition(stu);
        for (Student student : list) {
            System.out.println(student);
        }
    }

    @Test
    public void selectByIds(){
        List<Integer> listInteger = new ArrayList<>();
        listInteger.add(1);
        listInteger.add(2);
        listInteger.add(3);
        List<Student> list = service.selectByIds(listInteger);
        for (Student student : list) {
            System.out.println(student);
        }
    }
}
